package com.report.controller;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.report.dto.request.ReportReq;
import com.report.dto.response.ReportRes;
import com.report.entity.Report;
import com.report.service.IFileService;
import com.report.service.IReportService;
import com.zmh.framework.config.BaseCommonInterface;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author summer
 * @since 2024/06/25 14:54:53
 * 研报
 */
@RestController
@RequestMapping("/report")
@AllArgsConstructor
public class ReportController implements BaseCommonInterface<ReportReq, ReportRes> {

    private final IReportService reportService;

    private  final IFileService fileService;

    @Override
    public Result<String> save(@Valid ReportReq reportReq) {
        reportService.saveReport(reportReq);
        //更新文件选择状态
       // fileService.updateState(reportReq.getFileId());
        return Result.successResult();
    }

    @Override
    public Result<String> del(Integer id) {
        reportService.removeById(id);
        return Result.successResult();
    }

    @Override
    public Result<Page<ReportRes>> lists(ReportReq reportReq) {

        return Result.successResult(reportService.lists(reportReq));
    }

    @GetMapping(value = "/findList")
    public Result<List<ReportRes>> findList(){
        List<Report> list = reportService.list( Wrappers.lambdaQuery(Report.class).orderByDesc(Report::getCreateTime));
        return Result.successResult(Convert.toList(ReportRes.class,list));
    }

    @Override
    public Result<ReportRes> findById(Integer id) {
        Report byId = reportService.getById(id);
        return Result.successResult(Convert.convert(ReportRes.class,byId));
    }

    @Override
    public Result<String> batchDel(List<ReportRes> list) {
        return null;
    }
}
